/*
** CRITERR.C: Generate a Critical Error Manually.
*/

#include <pictor.h>
#include <dos.h>
#include <stdlib.h>
#include <mouse.h>

COLORSTRUCT msgcolors = {
   foreback(BLACK,CYAN),
   foreback(BOLD|WHITE,CYAN),
   foreback(WHITE,BLACK),
   foreback(BOLD|WHITE,BLACK)
};

int criterr(int, int);

void main(int argc, char * argv[])
{
	int error_code, return_code, block_char;
	if(argc == 1)
	{
		error_code = 0;
		block_char = 0;
	}
	else if(argc == 2)
	{
		error_code = atoi(argv[1]);
		block_char = 0;
	}
	else
	{
		error_code = atoi(argv[1]);
		block_char = atoi(argv[2]);
	}
		
   initvideo();
   cls();
   hookints(&msgcolors);
   
   /* Initialize mouse. */
   initmouse();
   showmouse();
   //system("COMMAND");
   //prnwrite(test, 13);
   return_code = criterr(error_code, block_char);
   
	if(return_code == 1)
	{
		messagebox("You decided to Retry.\n'Retry' here in PICTOR means 'Retry' in COMMAND.COM.", "Retry", MB_OK, &msgcolors);
	}
	else if(return_code == 3)
	{
		messagebox("You decided to Abort.\n'Abort' here in PICTOR means 'Fail' in COMMAND.COM.", "Abort AKA Fail", MB_OK, &msgcolors);
	}
	
	messagebox("Calling INT 24H directly, as in this program\nis HORRIFIC programming practice. Don't do it!", "Notice", MB_OK, &msgcolors);
	
   /* restore screen */
   vcolor(foreback(WHITE,BLACK));
   cls();
}

int criterr(int error, int bc)
{
	int r_code;
	__asm{
		mov ah, byte ptr bc
		mov di, error
		int 24h
		mov r_code, ax
	}
	return r_code;
}
